package com.lys.model.predicate;

import com.lys.ExampleMod;
import com.lys.enchantment.ModEnchantments;
import net.minecraft.client.item.ModelPredicateProviderRegistry;
import net.minecraft.enchantment.EnchantmentHelper;
import net.minecraft.item.Items;
import net.minecraft.util.Identifier;

public class ModelPredicate {

    static {
        /**
         * 匹配由于快速拉弓附魔的弓模型变化
         */
        ModelPredicateProviderRegistry.register(Items.BOW, new Identifier("pull"), (itemStack, clientWorld, livingEntity,seed) -> {
            if (livingEntity == null) {
                return 0.0f;
            }
            if (livingEntity.getActiveItem() != itemStack) {
                return 0.0f;
            }
            int level = EnchantmentHelper.getLevel(ModEnchantments.QUICK_PULLING, itemStack);
            if (level > 0){
                return (float)(itemStack.getMaxUseTime() - (livingEntity.getItemUseTimeLeft()*(1-level*0.0001F))) / 20.0f;
            }
            return (float)(itemStack.getMaxUseTime() - livingEntity.getItemUseTimeLeft()) / 20.0f;
        });
    }

    public static void registerPredicates(){
        ExampleMod.LOGGER.info("Registering ModPredicates");
    }
}
